-- bine_attack
-- create by cheny3
-- 魔藤主动攻击

return {
    -- 判断
    canTrigger = function(args)
        local bine = ME.user.bine;
        if not bine then
            return false;
        end

        local classId = bine.classId;
        if BineM.query(classId, "alias") ~= "magic_bine" then
            -- 不是魔藤
            return false;
        end

        -- 判断是否有存活的怪物
        local aliveMonsters = AutoFightM.getData()["aliveMonsters"];
        if aliveMonsters and #aliveMonsters > 0 then
            return true;
        end
        return false;
    end,

    -- 触发
    trigger = function(args)
        local chanceRange = args["chance"];
        if math.random(chanceRange[2]) > chanceRange[1] then
            -- 概率没发生
            return false;
        end

        local aliveMonsters = AutoFightM.getData()["aliveMonsters"];
        if not aliveMonsters or #aliveMonsters <= 0 then
            return false;
        end

        -- 主动技
        local skillId = BineM.getInitiativeSkill();
        -- 随机找一个
        local index = math.random(#aliveMonsters);
        local pos = aliveMonsters[index];

        -- 尝试攻击
        return DungeonActionM.go("bine_use_skill", pos, skillId);
    end,
};
